//
//  LGBaseInfoHeaderView.m
//  XieHeHeartDisease
//
//  Created by 1234 on 2024/5/30.
//

#import "LGBaseInfoHeaderView.h"

@interface LGBaseInfoHeaderView()

/**   */
@property (nonatomic , strong)UIView *baseView;


@end

@implementation LGBaseInfoHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}


-(void)editButtonAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(editBasicInfoAction:)]) {
        [self.delegate editBasicInfoAction:self.urlStr];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.editButton];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(viewPix(16));
        make.right.equalTo(self).offset(-viewPix(16));
        make.top.equalTo(self).offset(viewPix(8));
        make.bottom.equalTo(self).offset(viewPix(15));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(12));
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.titleLabel);
    }];
    
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.titleLabel);
        make.width.equalTo(@(Screen_W-viewPix(32)));
        make.height.equalTo(@(viewPix(35)));
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 10;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#000000" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _dateLabel;
}

-(UIButton *)editButton{
    if(!_editButton){
        _editButton = [UIButton buttonWithTitle:@"编辑" titleFont:LGFont(14) textColor:@"#909399" imageName:@"grayTip16"];
        _editButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _editButton.bounds = CGRectMake(0, 0, Screen_W-viewPix(32), viewPix(35));
        [_editButton setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
        [_editButton addTarget:self action:@selector(editButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editButton;
}

@end
